home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2404 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: gryphon.phoenix.net!usenet
  2. From: brucew@phoenix.net (Bruce Wedding)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with c code, please help!
  5. Date: Sun, 21 Jan 1996 04:56:26 GMT
  6. Organization: BranPaul Systems
  7. Message-ID: <4dseo8$19n@gryphon.phoenix.net>
  8. References: <surgsw-1901960148530001@128.206.206.86> <mikedorman-1901960725380001@205.148.200.150> <PRYE.96Jan20020251@ub239.dialup.uwa.edu.au>
  9. NNTP-Posting-Host: dial129.phoenix.net
  10. X-Newsreader: Moe's Newsreader    
  11.  
  12. prye@cyllene.uwa.edu.au (Peter Rye) wrote:
  13.  
  14. >>      char *word;
  15. >>
  16. >>      puts("Enter a word: ");
  17. >>      while(scanf("%s", word) != 0)
  18.  
  19. >I'm not sure that this is good advice.
  20.  
  21. Then let me assure you, it is lousy advice.  He is assigning 
  22. a string to a pointer that is not only unitialized, but also
  23. doesn't point to any memory that he owns.  If you do it this
  24. way, you have to allocate memory.  And I would advise him 
  25. to lose scanf also.  Use the tried and true combination of 
  26. fgets() and sscanf()
  27.  
  28.  
  29. Bruce D. Wedding                        Have Compiler, Will Travel!
  30.               Perspicacious Programming Performed Promptly
  31. Katy, Texas, USA, Planet Earth, Milkyway Galaxy, Known Universe
  32.  
  33.